#version 450 compatibility



#define ParallelLightNum 3
#define PointLightNum 6
#define SpotlightNum 6

layout( location = 0 ) out vec4 fFracColor;


//#ifdef DEF_Tessellation
//#else
in vec4 Normal;
in vec2 TCoord;








struct S_ParalleLight {
    vec4 m_Dir_Intensity;       //方向 强度
    vec4 m_Color_Attenuation;   //颜色 衰减
};
struct S_Spotlight {
    vec4 m_Location_Intensity;  //位置 强度
    vec4 m_Dir_Intensity;       //方向 角度
    vec4 m_Color_Attenuation;   //颜色 衰减
};


layout(std140, binding = 1) uniform u_LightCount {
    uvec4 m_LightCount;  //x 平行光数量, y 点光源数量 , z 聚光灯数量,
};
layout(std140, binding = 2) uniform _u_ParallelLight {
    S_ParalleLight m_ParalleLight[ ParallelLightNum ];
};
layout(std140, binding = 3) uniform _u_PointLight {
    S_ParalleLight m_PointLight[ PointLightNum ];
};
layout(std140, binding = 4) uniform _u_Spotlight {
    S_Spotlight m_Spotlight[ SpotlightNum ];
};

layout(std140, binding = 10) uniform _u_Diffuse {
    vec4 m_DiffuseColor;
    vec4 m_HighlightColor;
    vec4 m_AmbientColor;
    uint m_TexCount;
};
layout( location = 6 ) uniform sampler2D m_DiffuseTex;
layout( location = 7 ) uniform sampler2D m_HighlightTex;
layout( location = 8 ) uniform sampler2D m_AmbientTex;





void main(){
    uint ParalleLightCount = min(uint(ParallelLightNum), m_LightCount.x);
    uint PointLightCount = min(PointLightNum, m_LightCount.y);
    uint SpotlightCount = min(SpotlightNum, m_LightCount.z);
    

    vec3 diffuse = m_AmbientColor.rgb;
    vec3 parameterDiffuse = m_DiffuseColor.rgb*m_DiffuseColor.a + m_HighlightColor.rgb*m_HighlightColor.a;
    vec3 LightPos = vec3(0, 1, 0.3);
    //计算平行光照
    for(int i=0; i<ParalleLightCount; ++i){
        LightPos = m_ParalleLight[i].m_Dir_Intensity.xyz;
        diffuse += parameterDiffuse * max(0.0, dot(normalize(LightPos), normalize(Normal).xyz));
        
        //diffuse += parameterDiffuse * max(0.0, dot(normalize(LightPos), vec3(0.5,0.6,0.3)));
    }
    //diffuse = normalize(Normal).xyz;
    /*for(int i=0; i<PointLightCount; ++i){
    }

    for(int i=0; i<SpotlightCount; ++i){
    }*/

    //diffuse.rg = TCoord;
    //diffuse.b = 0.0;

    fFracColor = vec4(diffuse, 1.0);
}


